package com.eveinfo.api.utils.certificates;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.eveinfo.api.ApiResponse;

public class CertificatesResponse extends ApiResponse {

	private static final long serialVersionUID = -8672803593289517035L;
	
	private List<ApiCategory> categories;
	
	public CertificatesResponse() {
		categories = new ArrayList<ApiCategory>();
	}
	
	public boolean addCategory(ApiCategory category){
		return categories.add(category);
	}
	
	public List<ApiCategory> getCategories(){
		return categories;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(ApiCategory category : categories){
			sb.append(category+"\n");
		}
		return sb.toString();
	}
	
	public ApiCertificate getCertificate(int certificateID){
		ApiCertificate certificate = null;
		for(ApiCategory category : categories){
			certificate = category.getCertificate(certificateID);
			if(certificate != null){
				break;
			}
		}
		return certificate;
	}
	
	public void sort(){
		Collections.sort(categories);
		for(ApiCategory category : categories){
			category.sort();
		}
	}

}
